package com.intech.android.demo.cms.dao.impl;

import com.intech.android.demo.cms.dao.HibernateUtil;
import org.apache.log4j.Logger;
import org.hibernate.Session;

public class CommonDAO
{
    private static final Logger log = Logger.getLogger(CommonDAO.class);
    protected Session session;

    public CommonDAO()
    {
        log.debug("Try to receive current session");
        try
        {
            session = HibernateUtil.getSessionFactory().getCurrentSession();
            log.debug("Current session received =  [" + session.hashCode() + "]");
        }
        catch (Exception e)
        {
            log.debug("Cannot receive current sesssion");
        }
    }

    protected Session getCurrentSession()
    {
        if (session != null)
        {
            return session;
        }
        return HibernateUtil.getSessionFactory().getCurrentSession();
    }
}
